import BTDecorator from "../../Base/BTDecorator";
import { NodeStatus } from "../../Enum";


export default class DecoratorInverter extends BTDecorator
{
	onUpdate()
    {
        const res = this.childens[0].run();
        return this.declare(res);
	}


    canExecute(): boolean
    {
        return this.status === NodeStatus.Inactive || this.status === NodeStatus.Running;
    }

    onChildExecuted(childStatus: NodeStatus): void
    {
        this.status = childStatus;
    }


    declare(status: NodeStatus)
    {
        switch (status)
        {
            case NodeStatus.Failure:
                return NodeStatus.Success;
                break;
            case NodeStatus.Success:
                return NodeStatus.Failure;
                break;
            default:
                return status;
		}
    }
}